package com.yy.yyui.checkbox
{
	import com.siku.manor.config.Sys;
	import com.siku.manor.view.common.UM;
	import com.siku.manor.view.component.GT;
	import com.siku.manor.view.component.IDataContainer;
	import com.siku.manor.view.component.ISelectable;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class Checkbox extends Sprite implements ISelectable, IDataContainer
	{
		private var _data:Object;
		private var _actions:Object;
		private var bg:DisplayObject;
		private var cb:CheckLabel;
		private var lb:DisplayObject
		private var _enabled:Boolean;
		public function Checkbox(label:DisplayObject = null,selectSkin:DisplayObject=null,UnSelectSkin:DisplayObject = null,checkboxBackground:DisplayObject=null){	
			
			super();
			
			var dobj:DisplayObject;
			//add background
			bg = checkboxBackground==null?new UnSelected():checkboxBackground;
			bg.x = 0;
			bg.y = 2;
			this.addChild(bg);
			
			//add label
			if(label!=null)
			{
				dobj = this.addChild(label);
				dobj.x = bg.width;
				lb = dobj;
			}
			
			//add checklabel
			var un:DisplayObject = UnSelectSkin==null?UM.createEmptyDisplayObject(10,11):UnSelectSkin;
			cb = new CheckLabel(selectSkin,un);
			this.addChild(cb);

			
			//set actions
			this._actions = {};
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this.cb.onSelect = this.onSelect;
//			GT.enableClickDownOffsetEffect(this);
			
			
			
			this.cb.selected = false;
			this.buttonMode =  true;
			this._enabled = true;
			
			//GT.fulFill(this,0);
		}
		
		public function get label():DisplayObject{
			return this.lb;
		}
		
		public function get enabled():Boolean{
			return this._enabled;
		}
		
		public function set enabled(value:Boolean):void{
//			TextLabel(this.lb).textFormat.color = 0x202020;
//			TextLabel(this.lb).text = TextLabel(this.lb).text; 
			this.buttonMode = value;
			this.mouseChildren = value;
			this.mouseEnabled = value;
			if(value){
				this.filters = null;
			}else{
				this.buttonMode = false;
				this.filters = Sys.COMPONENT_DISABLE_FILTER;
			}
 
			this._enabled = value;
		}
		
		public function get data():Object
		{
			return _data;
		}
		public function set data(value:Object):void
		{
			this._data = value;
		}		
		
		public function get actions():Object
		{
			//TODO: implement function
			return this._actions;
		}
		
		public function get selected():Boolean
		{
			//TODO: implement function
			return this.cb.selected;
		}
		
		
		public function set selected(value:Boolean):void
		{
			//TODO: implement function
			this.cb.selected = value;
		}
		
		private function clickHandler(e:MouseEvent):void{
			if(!this.enabled) return;
			//if(this.cb.hitTestPoint(e.stageX,e.stageY)){
				//cb.defaultOnSelect(e);
				this.onSelect(e);
			//}
		}

		public function get onSelect():Function
		{
			//TODO: implement function
			
			return this.actions.onSelect;
		}
		
		public function set onSelect(value:Function):void
		{
			//TODO: implement function
			this.actions.onSelect = value;
		}
		
	}
}